package blue.logger;

import org.zeromq.ZMQ;

public class Subscriber{
	private ZMQ.Context zmq_ctx_;
	private ZMQ.Socket zmq_sock_;	
	private String ip_;
	private String port_;
	private String filter_;

	public Subscriber(String ip, String port, String filter){
        //  Prepare our context and publisher
        ip_ = ip;
        port_ = port;
        filter_ = filter;
        String endpoint = "tcp://"+ip_+":"+port_;
        zmq_ctx_ = ZMQ.context(1);
        //zmq_sock_ = zmq_ctx_.createSocket(ZMQ.SUB);
        zmq_sock_ = zmq_ctx_.socket(ZMQ.SUB);
        zmq_sock_.connect(endpoint);
        //  Subscribe to zipcode, default is NYC, 10001
        zmq_sock_.subscribe(filter_.getBytes(ZMQ.CHARSET));
        System.out.println("Subscribe Message from "+endpoint);        
	}

	public String recv(){
        return zmq_sock_.recvStr(ZMQ.DONTWAIT);
        //zmq_sock_.
	}
}
